# -*- coding: utf-8 –*-
import datetime

from mongoengine import StringField, IntField, BooleanField, \
    DateTimeField, ListField, ReferenceField, Document

from .mtu import Mtu
from .order import Order
from .destination import Destination


class PlanOrderMtu(Document):
    """
    计划中可预定的product, hotel
    """
    order = ReferenceField(Order, null=True)
    mtu = ReferenceField(Mtu, null=True)
    hotel_id = StringField(max_length=50)
    hotel_order_id = StringField(max_length=100)
    destination = ReferenceField(Destination, null=True)
    is_special = BooleanField(default=False)  # 是否是国家附加产品
    is_active = BooleanField(default=True)
    last_modified = DateTimeField(default=datetime.datetime.utcnow)
    date_added = DateTimeField(default=datetime.datetime.utcnow)

    meta = {
        'collection': 'vacation_planordermtu',
    }


class UserPlan(Document):
    """
    用户计划
    """
    user_id = IntField(null=True)
    name = StringField(max_length=100)
    city_names = StringField()  # 城市名，传给客户端用
    device_id = StringField()
    is_active = BooleanField(default=True)
    app_data = StringField()
    share_id = StringField(max_length=40)
    qiniu_cover = StringField()
    is_share = BooleanField(default=False)  # 是否分享过
    create_date = DateTimeField(default=datetime.datetime.utcnow)  # 计划创建日期，返回app
    last_modified = DateTimeField(default=datetime.datetime.utcnow)
    date_added = DateTimeField(default=datetime.datetime.utcnow)
    planordermtu = ListField(ReferenceField(PlanOrderMtu))

    meta = {
        'collection': 'vacation_userplan',
    }

    def get_info(self):
        return {
            "id": self.id,
            "last_modified": self.last_modified,
            "date_added": self.date_added,
            "cover": self.qiniu_cover if self.qiniu_cover else '',
            "name": self.name,
            "city_names": self.city_names,
        }
